namespace Voodoo.Sauce.Internal.IAP
{
	internal static class VoodooPremium
	{
		private const string TAG = "VoodooPremium";

		private const string PREFS_PREMIUM = "VoodooSauce.Premium";

		private const string PREMIUM_PERIOD = "VoodooSauce.PremiumPeriod";

		public static void SetEnabledPremium(bool enabled = true)
		{
			if (enabled == IsIAPPremium())
			{
				if (!enabled)
				{
					VoodooLog.LogError(Module.IAP, "VoodooPremium", "User is already premium, you should not be calling this method more than once, when the user bought your NO ADS in-app product");
				}
				return;
			}
			if (enabled)
			{
				VoodooLog.LogDebug(Module.IAP, "VoodooPremium", "User is now PREMIUM");
			}
			else
			{
				VoodooLog.LogDebug(Module.IAP, "VoodooPremium", "User isn't PREMIUM.");
			}
			NintendoPlayerPrefs.SetInt("VoodooSauce.Premium", enabled ? 1 : 0);
		}

		public static void SetPremiumPeriod(bool isPremiumPeriodActive)
		{
			if (isPremiumPeriodActive)
			{
				VoodooLog.LogDebug(Module.IAP, "VoodooPremium", "User is now in PREMIUM PERIOD");
				NintendoPlayerPrefs.SetInt("VoodooSauce.PremiumPeriod", 1);
				return;
			}
			VoodooLog.LogDebug(Module.IAP, "VoodooPremium", "User is now in NOT in PREMIUM PERIOD");
			if (HasPremiumPeriod())
			{
				NintendoPlayerPrefs.SetInt("VoodooSauce.PremiumPeriod", 0);
				IsPremium();
			}
		}

		public static void SetFreePeriod(bool isFreePeriodActive)
		{
			if (isFreePeriodActive)
			{
				VoodooLog.LogDebug(Module.IAP, "VoodooPremium", "User is now in PREMIUM PERIOD");
				NintendoPlayerPrefs.SetInt("VoodooSauce.PremiumPeriod", 1);
				return;
			}
			VoodooLog.LogDebug(Module.IAP, "VoodooPremium", "User is now in NOT in PREMIUM PERIOD");
			if (NintendoPlayerPrefs.GetInt("VoodooSauce.PremiumPeriod", 0) == 1)
			{
				NintendoPlayerPrefs.SetInt("VoodooSauce.PremiumPeriod", 0);
				IsPremium();
			}
		}

		public static bool IsPremium()
		{
			if (!IsIAPPremium())
			{
				return HasPremiumPeriod();
			}
			return true;
		}

		public static bool IsIAPPremium()
		{
			return NintendoPlayerPrefs.GetInt("VoodooSauce.Premium", 0) == 1;
		}

		public static bool HasPremiumPeriod()
		{
			return NintendoPlayerPrefs.GetInt("VoodooSauce.PremiumPeriod", 0) == 1;
		}
	}
}
